package com.cty.B_AllocationAndCollection.D_MaxTenuringThreshold02;

/**
 * @Auther: cty
 * @Date: 2020/6/29 23:03
 * @Description: 动态对象年龄判定
 * Minor GC时，若From Survivor中相同年龄对象达到或超过该区域容量的一半，
 * 该区域中大于等于该年龄的对象即使年龄没有达到 MaxTenureThreshold 参数设置值，也会直接移到老年代。
 * @VM Args: -XX:+PrintGCDetails -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=15
 * @version: 1.0
 */
public class MaxTenuringThreshold15_02 {

    private static final int _1MB = 1024 * 1024;

    public static void testMaxTenureThreshold(){
        byte[] allocation1, allocation2, allocation3, allocation4;

        allocation1 = new byte[_1MB / 4];  // ①
        allocation2 = new byte[_1MB / 4];  // ②
        allocation3 = new byte[4 * _1MB];  // ③
        allocation4 = new byte[4 * _1MB];  // 触发Minor GC  ④
        allocation4 = null;
        allocation4 = new byte[4 * _1MB];  // 触发Minor GC  ⑤
    }

    public static void main(String[] args) {
        testMaxTenureThreshold();
    }  // end main()

}  // end class

/**
 * [GC[DefNew: 5651K->931K(9216K), 0.0033244 secs] 5651K->5027K(19456K), 0.0033626 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
 * [GC[DefNew: 5191K->0K(9216K), 0.0010554 secs] 9287K->5025K(19456K), 0.0010805 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
 * Heap
 *  def new generation   total 9216K, used 4344K [0x33a00000, 0x34400000, 0x34400000)
 *   eden space 8192K,  53% used [0x33a00000, 0x33e3e118, 0x34200000)
 *   from space 1024K,   0% used [0x34200000, 0x34200088, 0x34300000)
 *   to   space 1024K,   0% used [0x34300000, 0x34300000, 0x34400000)
 *  tenured generation   total 10240K, used 5025K [0x34400000, 0x34e00000, 0x34e00000)
 *    the space 10240K,  49% used [0x34400000, 0x348e8488, 0x348e8600, 0x34e00000)
 *  compacting perm gen  total 12288K, used 234K [0x34e00000, 0x35a00000, 0x38e00000)
 *    the space 12288K,   1% used [0x34e00000, 0x34e3aaa8, 0x34e3ac00, 0x35a00000)
 *     ro space 10240K,  44% used [0x38e00000, 0x3927aee0, 0x3927b000, 0x39800000)
 *     rw space 12288K,  52% used [0x39800000, 0x39e42e10, 0x39e43000, 0x3a400000)
 */
